<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<link rel="stylesheet" type="text/css" href="{{CDN}}/easyui/themes/default/easyui.css">
		<link rel="stylesheet" type="text/css" href="{{CDN}}/easyui/themes/icon.css">
		<script type="text/javascript" src="{{CDN}}/easyui/jquery.min.js"></script>
		<script type="text/javascript" src="{{CDN}}/easyui/jquery.easyui.min.js"></script>
		<script type="text/javascript" src="{{CDN}}/easyui/locale/easyui-lang-zh_CN.js"></script>
		<script>
		var selectRow = null
		$(function(){
			$("#left_grid").datagrid({
				singleSelect:true,
				fit:true,
				fitColumns:true,
				collapsible:true, 
				striped:true,
				rownumbers:true, 
				columns:[[    
			    	{field:'CK',checkbox:true},
			    	{field:'id',title:'id',width:20,align:'left'},
			    	{field:'apt_code',title:'apt_code',width:30,align:'left'},
			        {field:'lx',title:'类型',width:70,align:'left'},
			        {field:'dl',title:'大类',width:100,align:'left'},
			        {field:'xl',title:'小类',width:100,align:'left'},
			        {field:'zy',title:'专业',width:100,align:'left'},
			        {field:'web_show',title:'前端展示',width:100,align:'left'}
			    ]],
                url:'/commonDict/companyCertDict/getCompanyCertDictList',
                queryParams: parent.getFormJson($("#search_form")),
			    onClickRow:function(rowIndex, row){
					selectRow= row;
					$("#grid").datagrid({
						title:row.lx+","+row.dl+","+row.xl+","+row.zy+"添加一级映射",
						url:'/commonDict/companyCertDict/getCertMappingById',
						queryParams:{id:row.id}
					});
				}
			})
			
			//查询按钮
			$("#search_btn").click(function(){
				$("#left_grid").datagrid({
					url:'/commonDict/companyCertDict/getCompanyCertDictList',
					queryParams: parent.getFormJson($("#search_form"))
				})
			});
			
			//左侧修改按钮
			$("#edit_btn").click(function(){
				var rows = $('#left_grid').datagrid('getSelections');
				if(rows.length<1){
					$.messager.alert('提示','请勾选一条');
					return false;
				}
				$("#edit_id").textbox("setValue", rows[0].id);
				$("#edit_lx").textbox("setValue", rows[0].lx);
				$("#edit_dl").textbox("setValue", rows[0].dl);
				$("#edit_xl").textbox("setValue", rows[0].xl);
				$("#edit_zy").textbox("setValue", rows[0].zy);
				$("#edit_web_show").textbox("setValue", rows[0].web_show);
				
				$("#edit_dialog").dialog({ 
					title: '修改',    
					width: 1000,    
					height: 500,    
					closed: false,    
					cache: false,
			   		modal: true,
			   		buttons:[{
						text:'保存',
						iconCls:'icon-save',
						handler:function(){
							$.post("/commonDict/companyCertDict/updateCompanyCertDict",parent.getFormJson($('#edit_form')),function(response){
								
								$("#edit_dialog").dialog('close');
								$("#left_grid").datagrid({
									url:'/commonDict/companyCertDict/getCompanyCertDictList',
									queryParams: parent.getFormJson($("#search_form"))
								})
							})
						
						}
					}]
				});
			});
			$("#del_btn").click(function(){
				var rows = $('#left_grid').datagrid('getSelections');
				if(rows.length<1){
					$.messager.alert('提示','请勾选一条');
					return false;
				}
				$.post("/commonDict/companyCertDict/deleteById",{id:rows[0].id},function(response){
					$("#left_grid").datagrid({
						url:'/commonDict/companyCertDict/getCompanyCertDictList',
						queryParams: parent.getFormJson($("#search_form"))
					})
				})
			});
			
			
			/*表格初始化*/
			$("#grid").datagrid({
				singleSelect:true,
				fit:true,
				fitColumns:true,
				collapsible:true, 
				striped:true,
				rownumbers:true, 
			    columns:[[    
			    	{field:'CK',checkbox:true},
			    	{field:'data_source_num',title:'数据源',width:15,align:'left'},
			        {field:'alias_name',title:'脏数据名称',width:100,align:'left'}
			    ]],
			    toolbar: [{
					iconCls: 'icon-add',
					text:'新增',
					handler: function(){

						$("#add_dialog").dialog({ 
							title: '添加名称',    
							width: 800,    
							height: 220,    
							closed: false,    
							cache: false,
					   		modal: true,
					   		buttons:[{
					   			text:'保存',
								iconCls:'icon-save',
								handler:function(){
									$.post("/commonDict/companyCertDict/addCertMapping",{
										data_source_num:$("#data_source_num").textbox("getValue"),
										alias_name:$("#alias_name").textbox("getValue"),
										cert_dict_id:selectRow.id
									},function(response){
										$("#add_dialog").dialog('close');
										$("#grid").datagrid('reload');
									})
								}
					   		}]
						});
					}
				},'-',{
					iconCls: 'icon-edit',
					text:'修改',
					handler: function(){
						var rows = $('#grid').datagrid('getSelections');
						if(rows.length<1){
							$.messager.alert('提示','请勾选一条');
							return false;
						}
						$("#alias_name").textbox("setValue",rows[0].alias_name);
						$("#data_source_num").textbox("setValue",rows[0].data_source_num);
						$("#add_dialog").dialog({ 
							title: '修改名称',    
							width: 800,    
							height: 220,    
							closed: false,    
							cache: false,
					   		modal: true,
					   		buttons:[{
					   			text:'保存',
								iconCls:'icon-save',
								handler:function(){
									$.post("/commonDict/companyCertDict/updateCertMapping",{
										mapping_id:rows[0].alias_id,
										data_source_num:$("#data_source_num").textbox("getValue"),
										alias_name:$("#alias_name").textbox("getValue"),
										cert_dict_id:selectRow.id
									},function(response){
										$("#add_dialog").dialog('close');
										$("#grid").datagrid('reload');
									})
								}
					   		}]
						});
					}
				},'-',{
					iconCls: 'icon-search',
					text:'查看未匹配数据',
					handler: function(){
						$("#show_grid").datagrid({
							url:'/commonDict/companyCertDict/getCompanyCertUnMatch',
							singleSelect:true,
							fit:true,
							fitColumns:true,
							collapsible:true, 
							striped:true,
							rownumbers:true, 
						    columns:[[    
						        {field:'original',title:'未匹配名称',width:100,align:'left'},
						        {field:'data_source_code',title:'数据源',width:100,align:'left'}
						    ]],
						    toolbar:[{
					   			text:'清除全部',
								iconCls:'icon-del',
								handler:function(){
									$.post("/commonDict/companyCertDict/deleteUnMatch",{},function(response){
										$("#show_grid").datagrid('reload');
									})
								}
					   		}]
						});
						
						$("#show_dialog").dialog({ 
							width: 900,    
							height: 700,    
							closed: false,    
							cache: false,
					   		modal: true
						})
					}
				}]

			});
		});
		
		</script>
	</head>
	<body class="easyui-layout">
		<div region="center" border="false" width="80%" title="资质专业标准字典维护">
			<div id = 'toolbar'>
				<!-- 查询条件表单 -->
				<form id ="search_form" method="post" class="easyui-form">
					<table width="100%">
						<tr align = "left">
							<td align="right" width="20%">关键字:</td>
							<td width="20%"  align="left" >
								<input class="easyui-textbox"  name="key_str" style="width:500px"  />
							</td>
						<td width="20%"  align="left" >
							<a href="#" id="search_btn" class="easyui-linkbutton"	 data-options="iconCls:'icon-search'"  >查询</a>
							<a href="#" id="edit_btn" class="easyui-linkbutton"	 data-options="iconCls:'icon-search'"  >修改</a>
							<a href="#" id="del_btn" class="easyui-linkbutton"	 data-options="iconCls:'icon-search'"  >删除</a>
						</td>	
						</tr>
					</table>
				</form>
			</div>
			 <table id="left_grid"  toolbar = '#toolbar'></table>
		</div>
		
		
		<div region = "east" border = "false"  width="35%" title="映射关系">
			<table id="grid"></table>
		</div>

		<div style="display:none" id="add_dialog">
				<table width="100%">
					</tr>
						<td align="right" width="20%">数据源:</td>
						<td width="20%"  align="left">
							<select class="easyui-textbox" id = "data_source_num"  name="data_source_num" style="width:400px">
						</td>
						<td width="20%" ></td>
					</tr>
					</tr>
						<td align="right" width="20%">名称:</td>
						<td width="20%"  align="left">
							<select class="easyui-textbox" id = "alias_name"  name="alias_name" style="width:400px">
						</td>
						<td width="20%" ></td>
					</tr>
				</table> 
		</div>
		
		
		
		<div style="display:none" id="show_dialog">
			<table id="show_grid" ></table>
		</div>
		
		
		
		<!-- 一些隐藏的对话框 -->
		<!-- 左侧修改页 -->
		<div style="display:none" id="edit_dialog">
			<form id ="edit_form" method="post" >   
				<table width="100%">
					
					<tr style="display:none">
						<td align="right" width="20%">id:</td>
						<td width="20%"  align="left" >
							<input class="easyui-textbox"  id="edit_id"  name="id" style="width:700px"  />
						</td>
					<tr>
					
					<tr>
						<td align="right" width="20%">类型:</td>
						<td width="20%"  align="left" >
							<input class="easyui-textbox"  id="edit_lx"  name="lx" style="width:700px"  />
						</td>
					<tr>
					</tr>
						<td align="right" width="20%">大类:</td>
						<td width="20%"  align="left">
							<select class="easyui-textbox"  id="edit_dl" name="dl"  style="width:700px">
						</td>
						<td width="20%" ></td>
					</tr>
					</tr>
						<td align="right" width="20%">小类:</td>
						<td width="20%"  align="left">
							<select class="easyui-textbox" id="edit_xl" name="xl" style="width:700px">
						</td>
						<td width="20%" ></td>
					</tr>
					</tr>
						<td align="right" width="20%">专业:</td>
						<td width="20%"  align="left">
							<select class="easyui-textbox" id="edit_zy" name="zy" style="width:700px">
						</td>
						<td width="20%" ></td>
					</tr>
					</tr>
						<td align="right" width="20%">前端展示:</td>
						<td width="20%"  align="left">
							<select class="easyui-textbox" id="edit_web_show" name="web_show" style="width:700px">
						</td>
						<td width="20%" ></td>
					</tr>
				</table> 
			</form>
		</div> 
		
		
		
		
		
		
		
		
		
	</body>
</html>
